import {Utils} from '../utils/Utils';
import {AjaxMsg} from '../utils/AjaxMsg';

export class LoginSubmitButton {
    constructor(form, dom){
        this.form = form;
        this.app = form.app;
        this.api = form.app.api;
        this.dom = dom;

        this._defaultLabel = this.dom.text();
        this._disabled = false;

        this.dom.on('click', this.onClick.bind(this));
    }

    disable(message = null){
        if(!this.disable){
            this.dom.prop('disabled', true);
        }
        if(message){
            this.dom.text(message);
        }
        this._disabled = true;
    }

    enable(){
        this.dom.prop('disabled', false);
        this.dom.text(this._defaultLabel);
        this._disabled = false;
    }

    onClick(event){
        event.preventDefault();
        this.form.doLogin();
    }
}